/**
 * 时间戳转成为 年月日 时分秒
 * @param timestamp 时间戳
 * **/
export const timestampToStr =  (timestamp) => {
  if (!timestamp) return ''
  var date = new Date(timestamp)
  var Y = date.getFullYear() + '-'
  var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-'
  var D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' '
  var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':'
  var m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':'
  var s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
  return Y + M + D + h + m + s
}

/**
 * 时间戳转成为 月日 时分
 * @param timestamp 时间戳
 * **/
export const timestampToStr2 =  (timestamp) => {
  if (!timestamp) return ''
  var date = new Date(timestamp)
  var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-'
  var D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' '
  var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':'
  var m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes())
  return M + D + h + m
}

/**
 * 秒转成为 天/小时/分钟/秒
 * @param count 秒
 * **/
export const formattingTime = (count) => {
  if(!count) return '0秒'
	var time = ''
	var second = count % 60
	var minute = parseInt(parseInt(count) / 60) % 60
	time = second + "秒"
	if (minute >= 1 ) {
		time = minute + "分" +second + "秒"
	}
	var hour = parseInt( parseInt(count / 60) / 60 ) % 24
	if ( hour >= 1 ) {
		time = hour + "小时" + minute + "分" + second + "秒"
	}
	var day = parseInt( parseInt( parseInt(count / 60) / 60 ) / 24 )
	if ( day >= 1 ) {
		time = day + "天" + hour + "小时" + minute + "分" + second + "秒"
	}
	return time
}

/**
 * 秒转成为 天:小时:分钟:秒
 * @param count 秒
 * **/
export const formattingTime2 = (count) => {
  if(!count) return '0'
	var time = ''
	var second = count % 60
	var minute = parseInt(parseInt(count) / 60) % 60
	time = second
	if (minute >= 1 ) {
		time = minute + ":" +second
	}
	var hour = parseInt( parseInt(count / 60) / 60 ) % 24
	if ( hour >= 1 ) {
		time = hour + ":" + minute + ":" + second
	}
	var day = parseInt( parseInt( parseInt(count / 60) / 60 ) / 24 )
	if ( day >= 1 ) {
		time = day + ":" + hour + ":" + minute + ":" + second
	}
	return time
}

/**
 * 秒转成为 天:小时:分钟:秒
 * @param seconds 秒
 * **/
export const formattingTime3 = (seconds) => {
	if(!seconds) return '00:00:00'
	let hour = Math.floor(seconds / 3600) >= 10 ? Math.floor(seconds / 3600) : '0' + Math.floor(seconds / 3600);
	seconds -= 3600 * hour;
	let min = Math.floor(seconds / 60) >= 10 ? Math.floor(seconds / 60) : '0' + Math.floor(seconds / 60);
	seconds -= 60 * min;
	let sec = seconds >= 10 ? seconds : '0' + seconds;
	return hour + ':' + min + ':' + sec
}

/**
 * 秒转成为 天:小时:分钟:秒
 * @param count 秒
 * **/
export const formattingTime4 = (count) => {
	if (!count || count <=0) return '0分'
	// let seconds = count
	let hours = Math.floor(count / 3600)
	let minutes = Math.floor((count - (hours * 3600)) / 60)

	return hours + '时' + minutes + '分'
}

/**
 * 判断两个日期时间组件是否相差 ***  
 * @param time 日期时间
 * @param millisecond 相差xxx毫秒
 * **/
export const timeMathAbs = (time, millisecond) => {
	if (!time) return true

	// 判断是否是同一日期
	// 判断时间相差
	let oldTimen = new Date(time).getTime() + millisecond
	let newTime = new Date().getTime()
	if (oldTimen < newTime) {
		return true
	}

	return false
}